// Object_.cpp: implementation of the Object_ class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Object_.h"
#include "ManagerTemplate.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

UE_BASE_IMPLEMENT_DYNAMIC(Object_);

Object_::Object_()
{

}

Object_::~Object_()
{

}
/*
#ifdef _AFXDLL
AFX_COMDAT const AFX_DATADEF struct RuntimeClass_ Object_::classObject_ =
	{ "Object_", sizeof(Object_), 0xffff, NULL, NULL, NULL };
#else
AFX_COMDAT const AFX_DATADEF struct RuntimeClass_ Object_::classObject_ =
	{ "Object_", sizeof(Object_), 0xffff, NULL, NULL, NULL };
#endif

const RuntimeClass_* Object_::GetRuntimeClass() const
{
	return UE_RUNTIME_CLASS(Object_);
}

const RuntimeClass_* Object_::RuntimeClass(){
	return &classObject_;
}

BOOL Object_::IsKindOf(const RuntimeClass_* pClass) const
{
	ASSERT(this != NULL);
	// it better be in valid memory, at least for Object_ size
	ASSERT(AfxIsValidAddress(this, sizeof(Object_)));

	// simple SI case
	const RuntimeClass_* pClassThis = GetRuntimeClass();
	return pClassThis->IsDerivedFrom(pClass);
}


Object_* RuntimeClass_::CreateObject()
{
	if (m_pfnCreateObject == NULL)
	{
		TRACE(_T("Error: Trying to create object which is not ")
			  _T("DECLARE_DYNCREATE \nor DECLARE_SERIAL: %hs.\n"),
			m_lpszClassName);
		return NULL;
	}

	Object_* pObject = NULL;
	TRY
	{
		pObject = (*m_pfnCreateObject)();
	}
	END_TRY

	return pObject;
}

BOOL RuntimeClass_::IsDerivedFrom(const RuntimeClass_* pBaseClass) const
{
	ASSERT(this != NULL);
	ASSERT(AfxIsValidAddress(this, sizeof(RuntimeClass_), FALSE));
	ASSERT(pBaseClass != NULL);
	ASSERT(AfxIsValidAddress(pBaseClass, sizeof(RuntimeClass_), FALSE));

	// simple SI case
	const RuntimeClass_* pClassThis = this;
	if(pClassThis == NULL)
		return FALSE;

	if (pClassThis == pBaseClass)
		return TRUE;

	const BaseClassList_* pBaseClassList = m_pBaseList;
	if(pBaseClassList == NULL)
		return FALSE;

	while(pBaseClassList->m_Status != eUNVALID)
	{
		pClassThis = pBaseClassList->m_pBaseClass;

		if(pClassThis->IsDerivedFrom(pBaseClass))
			return TRUE;

		pBaseClassList++;
	}
	return FALSE;       // walked to the top, no match
}
*/


BOOL TypeCast<CString, INT>(const CString& i, INT& o)
{
	o = atoi(i);
	return TRUE;
}

BOOL TypeCast<CString, DOUBLE>(const CString &i, DOUBLE& o)
{
	o = atof(i);
	return TRUE;
}

BOOL TypeCast<CString, LONG>(const CString& i, LONG& o)
{
	o = atol(i);
	return TRUE;
}

BOOL TypeCast<CString, unsigned long>(const CString& i, unsigned long& o)
{
	o = atol(i);
	return TRUE;
}

BOOL TypeCast<INT, CString>(const INT& i, CString& o)
{
	o.Format(_T("%d"), i);
	return TRUE;
}

BOOL TypeCast<DOUBLE, CString>(const DOUBLE& i, CString& o)
{
	o.Format(_T("%g"), i);
	return TRUE;
}

BOOL TypeCast<LONG, CString>(const LONG& i, CString& o)
{
	o.Format(_T("ld"), i);
	return TRUE;
}

BOOL TypeCast<unsigned long, CString>(const unsigned long& i, CString& o)
{
	o.Format(_T("ld"), i);
	return TRUE;
}